<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.7.13/dingtalk.open.js"></script>
<script type="text/javascript">
    dd.config({
        agentId: _config.agentId,
        corpId: _config.corpId,
        timeStamp: _config.timeStamp,
        nonceStr: _config.nonceStr,
        signature: _config.signature,
        jsApiList: [
            'biz.contact.complexPicker'
        ]
    });
    dd.userid=0;
    dd.ready(function () {

        $('.chooseonebtn').on('click', function() {
            dd.biz.contact.departmentsPicker({
                title:"测试标题",            //标题
                corpId:"xxx",              //企业的corpId
                multiple:true,            //是否多选
                limitTips:"超出了",          //超过限定人数返回提示
                maxDepartments:100,            //最大选择部门数量
                pickedDepartments:[],          //已选部门
                disabledDepartments:[],        //不可选部门
                requiredDepartments:[],        //必选部门（不可取消选中状态）
                appId:158,              //微应用的Id
                permissionType:"xxx",          //选人权限，目前只有GLOBAL这个参数
                onSuccess: function(result) {
                    var depts = result.departments;
                    for(i in depts) {
                        //获得属性

                        alert(depts[i].id);

                    }
                    /**
                     {
            userCount:1,                              //选择人数
            departmentsCount:1，//选择的部门数量
            departments:[{"id":,"name":"","number":}]//返回已选部门列表，列表中每个对象包含id（部门id）、name（部门名称）、number（部门人数）
        }
                     */
                },
                onFail : function(err) {}
            });
        });
    });
    dd.error(function(error){
        /**
         {
           errorMessage:"错误信息",// errorMessage 信息会展示出钉钉服务端生成签名使用的参数，请和您生成签名的参数作对比，找出错误的参数
           errorCode: "错误码"
        }
         **/
        alert('dd error: ' + JSON.stringify(error));
    });

</script>
</head>
<body>

<h1>-手动派发任务-</h1>


<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('AdminIndex/index')}">任务列表</a></li>
        <li class="active"><a href="{:url('AdminIndex/add')}">发布任务</a></li>
        <li><a href="{:url('AdminIndex/add2')}">批量任务</a></li>
    </ul>
    <form action="{:url('AdminIndex/addpost')}" method="post" class="form-horizontal js-ajax-form margin-top-20" onsubmit="return validate_form(this)">
        <div class="row">
            <div class="col-md-9">
                <table class="table table-bordered">

                    <tr>
                        <th>任务标题<span class="form-required">*</span></th>
                        <td id="title_td" class="must_choose">
                            <input class="form-control" type="text" name="title"
                                   id="title" value="" placeholder="请输入任务标题" onclick="setBackground()"/>
                        </td>
                    </tr>

                    <tr>
                        <th>任务内容<span class="form-required">*</span></th>
                        <td>

                            <textarea placeholder="请输入任务内容" name="task_content" type="text" style="width:770px; height:100px"></textarea>

                        </td>
                    </tr>
                    <tr>
                        <th>接收人<span class="form-required">*</span></th>
                        <td>
                            <form class="layui-form" action="" lay-filter="example">


                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <input type="text" name="depts" id="depts"/>
                                        <button type="button" class="layui-btn layui-btn-primary chooseonebtn">选择部门</button>
                                    </div>
                                </div>
                            </form>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <label>任务种类<span class="form-required">*</span></label>
                        </th>
                        <td>

                            <select name="type">
                                <option value="0">通知</option>
                                <option value="1">市场</option>
                                <option value="2">网运</option>
                                <option value="3">人事</option>
                            </select>

                        </td>
                    </tr>

                    <tr>
                        <th>
                            <label>任务标签<span class="form-required">*</span></label>
                        </th>
                        <td>

                            <select name="tag">
                                <option value="0">通知类无需回复附件</option>
                                <option value="1">处理人必须上传附件</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <th>
                            <label>截止日期<span class="form-required">*</span></label>
                        </th>
                        <td id="deadline_td" class="must_choose">

                            <input type="text" class="form-control js-bootstrap-datetime" name="deadline"
                                   value="{$start_time|default=''}"
                                   style="width: 160px;" autocomplete="off" onclick="setBackground()">
                        </td>
                    </tr>

                    <tr>
                        <th>
                            <label>选择附件(可选)</label>
                        </th>
                        <td id="files_td" class="must_choose">

                            <ul id="files" class="pic-list list-unstyled form-inline">
                            </ul>
                            <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl','file')"
                               class="btn btn-sm btn-default" onclick="setBackground()">选择文件</a>
                        </td>
                    </tr>


                </table>



                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary">发布任务</button>
                        <a class="btn btn-default" href="{:url('AdminIndex/index')}">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

    });
    function setBackground() {
        $("td.must_choose").attr("style","background-color: #ffffff");
    }
    function validate_form(thisform)
    {

        if (thisform.title.value==null||thisform.title.value==''){
            $("td#title_td").attr("style","background-color: #ffe5e5 ");
            return false
        }
        if (thisform.deadline.value==null||thisform.deadline.value==''){
            $("td#deadline_td").attr("style","background-color: #ffe5e5 ");
            return false
        }

        return true

    }


    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin   = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>

</body>
</html>
